package com.hyg.module_third_party_demo.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.hyg.lib_base.mainUtils.StatusBarUtil;
import com.hyg.lib_common.Base.BaseActivity;
import com.hyg.lib_common.constant.Constants;
import com.hyg.module_third_party_demo.R;
import com.hyg.module_third_party_demo.entity.User;
import com.hyg.module_third_party_demo.rxbus.RxBus;

import io.reactivex.functions.Consumer;

@Route(path = Constants.PATH_ACTIVITY_MODULE_DEMO_MAIN)
public class ThirdPartyDemoMainActivity extends BaseActivity {
    LinearLayout linearLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third_party_demo_main);
//        StatusBarUtil.setStatusBarTextColor(this, true);
//        StatusBarUtil.setDarkMode(this);
        StatusBarUtil.setLightMode(this);
        StatusBarUtil.setColor(this, Color.rgb(200, 30, 30), 0);
        initView();
    }

    public void initView() {
        subscribe();
        linearLayout = findViewById(R.id.ln_content_group);
        addItem("LitePal数据库", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_LITEPAL, false);
            }
        });
        addItem("Arouter路由", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_AROUTER, false);
            }
        });

        addItem("StatusBar状态栏", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_STATUSBAR, false);
            }
        });

        addItem("UCrop图片裁剪", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_UCROP, false);
            }
        });

        addItem("SmartRefreshLayoutActivity", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_SMARTREFRESH, false);
            }
        });

        addItem("FastJsonActivity", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_FASTJSON, false);
            }
        });

        addItem("Retrofit网络请求", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_RETROFIT, false);
            }
        });

        addItem("okhttp网络请求", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_OKHTTP, false);
            }
        });

        addItem("Glide图片处理", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_GLIDE, false);
            }
        });

        addItem("RxAndroid", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToIntent(Constants.PATH_ACTIVITY_MODULE_DEMO_RXANDROID, false);
            }
        });
//        StatusBarUtil.setColor(this, getResources().getColor(R.color.red), 0);
    }

    public void addItem(String string, View.OnClickListener listener) {
        Button newBtn = new Button(this);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(0, 50, 0, 0);
        newBtn.setLayoutParams(params);
        newBtn.setText(string);
        newBtn.setAllCaps(false);
        newBtn.setOnClickListener(listener);
        linearLayout.addView(newBtn);
    }

    /**
     * 订阅
     */
    public void subscribe() {
        RxBus.getInstance().subscribe(User.class, new Consumer<User>() {
            @Override
            public void accept(User user) throws Exception {
            }
        });
    }

}